require.config({
    paths: {
        "cache": "lib/cache"
    }
});
require(['cache'], function(cache) {
    $("#login").click(function() {
        $.ajax({
            url: '/public/login.html',
            type: 'POST',
            contentType: "application/x-www-form-urlencoded",
            data: $("form").serialize(),
            success: function(data, status, xhr) {
                var login_user = {
                    token: xhr.getResponseHeader('X-AuthToken'),
                    username: $("#username").val(),
                };
                cache.ready();
                cache.go(login_user);
                if (xhr.getResponseHeader('CK-pwd') < 0) {
                    // debugger;
                    dialog().content("您的密码过于简单，请修改密码").showModal();
                    setTimeout(function() {
                        window.location = "/changepwd";
                    }, 2000); 
                    return;
                }
                
                window.location = "/";
            },
            error: function(data, status, xhr) {
                var info = JSON.parse(data.responseText).msg;
                if (info.indexOf(":") > 0) {
                	info = info.substr(info.indexOf(":") + 1);
                }
                $("#errorInfo").text(info);
                refreshing();
                // setTimeout(function() { $("#errorInfo").text(""); }, 2000);
            }
        });
        return false;
    });

});

function refreshing() {
    document.getElementById("verifyCodeImg").src = "/public/verificationCode?" + Math.random();;
}
